//
//  HomeServiceListCell.m
//  DingDongXiChe
//
//  Created by wtjr on 2018/1/4.
//  Copyright © 2018年 xieyingze. All rights reserved.
//

#import "HomeServiceListCell.h"
#import "UIImageView+WebCache.h"

@interface HomeServiceListCell()

@property (nonatomic, strong) UIView *mainView;

@property (nonatomic, strong) BaseImageView *iconImageView;

@property (nonatomic, strong) BaseLabel *titleLabel;

@property (nonatomic, strong) BaseLabel *descriptionLabel;

@property (nonatomic, strong) BaseLabel *distanceLabel;

@end

@implementation HomeServiceListCell

+ (instancetype)cellWithTableView:(UITableView *)tableView indexPath:(NSIndexPath *)indexPath {
    tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    static NSString *cellId = @"HomeServiceListCell";
    HomeServiceListCell *cell = [tableView dequeueReusableCellWithIdentifier:cellId];
    if (cell == nil) {
        cell = [[HomeServiceListCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellId];
    }
    return cell;
}

#pragma mark - init

- (void)initSubView {
    [self addSubview:self.mainView];
}

- (void)autoLayoutSubviews {
    [self.mainView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(@0);
    }];
}

- (void)bindViewModel {
    
}

- (void)setModel:(ServiceModel *)model {
    self.titleLabel.text = model.service_title;
    self.descriptionLabel.text = model.service_description;
    self.distanceLabel.text = [NSString stringWithFormat:@"%.2fkm",model.distance/1000];
    [self.iconImageView sd_setImageWithURL:[NSURL URLWithString:model.service_shopUrl] placeholderImage:[UIImage imageNamed:kDefaultImage] options:SDWebImageRetryFailed];
    _model = model;
}

#pragma mark - Method


#pragma mark - Interface


#pragma mark - Setter


#pragma mark - Getter

- (UIView *)mainView {
    if (!_mainView) {
        _mainView = [UIView new];
        
        BaseImageView *iconImageView = [BaseImageView new];
        iconImageView.imageName = kDefaultImage;
        iconImageView.layer.cornerRadius = 20;
        iconImageView.layer.masksToBounds = YES;
        self.iconImageView = iconImageView;
        [_mainView addSubview:iconImageView];
        [iconImageView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(@20);
            make.centerY.equalTo(@0);
            make.width.height.equalTo(@40);
        }];
        
        BaseLabel *titleLabel = [BaseLabel new];
        [titleLabel setLabelStyle:@"" textColor:KCOLOR_font_normal textFont:kFONT_mainNumBoldFont(12) texrAlignment:NSTextAlignmentLeft];
        self.titleLabel = titleLabel;
        [_mainView addSubview:titleLabel];
        [titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(iconImageView);
            make.left.equalTo(iconImageView.mas_right).offset(10);
            make.height.equalTo(@20);
        }];
        
        BaseLabel *descriptionLabel = [BaseLabel new];
        [descriptionLabel setLabelStyle:@"" textColor:KCOLOR_font_tint textFont:kFONT_mainFont(10) texrAlignment:NSTextAlignmentLeft];
        self.descriptionLabel = descriptionLabel;
        [_mainView addSubview:descriptionLabel];
        [descriptionLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(titleLabel.mas_bottom).offset(5);
            make.left.equalTo(titleLabel);
            make.height.equalTo(@10);
        }];
        
        BaseLabel *distanceLabel = [BaseLabel new];
        [distanceLabel setLabelStyle:@"" textColor:KCOLOR_font_tint textFont:kFONT_mainFont(10) texrAlignment:NSTextAlignmentRight];
        self.distanceLabel = distanceLabel;
        [_mainView addSubview:distanceLabel];
        [distanceLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.equalTo(@-20);
            make.centerY.equalTo(titleLabel);
            make.height.equalTo(@10);
        }];
    }
    return _mainView;
}

@end
